'use strict';

import { basicAction } from '@peace/utils';
import { ApiTable } from '$utils';

// 获取商标列表（分页）
export function getTrademarkList(params) {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'GET_TRADEMARK_LIST',
    url: `${ApiTable.getTrademarkList}`,
    query: params,
    msg: { error: '获取商标列表失败' },
    reducer: { name: 'trademarkList' }
  });
}

// 获取商标详情
export function getTrademarkDetail(id) {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'GET_TRADEMARK_DETAIL',
    url: `${ApiTable.getTrademarkDetail.replace(':id', id)}`,
    msg: { error: '获取商标详情失败' },
    reducer: { name: 'trademarkDetail' }
  });
}

// 新增商标
export function addTrademark(data) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'ADD_TRADEMARK',
    url: `${ApiTable.addTrademark}`,
    data: data,
    msg: { error: '添加商标失败' },
    reducer: { name: 'addTrademarkResult' }
  });
}

// 编辑商标
export function updateTrademark(id, data) {
  return dispatch => basicAction({
    type: 'put',
    dispatch: dispatch,
    actionType: 'UPDATE_TRADEMARK',
    url: `${ApiTable.updateTrademark.replace(':id', id)}`,
    data: data,
    msg: { error: '更新商标失败' },
    reducer: { name: 'updateTrademarkResult' }
  });
}

// 删除商标
export function deleteTrademark(id) {
  return dispatch => basicAction({
    type: 'delete',
    dispatch: dispatch,
    actionType: 'DELETE_TRADEMARK',
    url: `${ApiTable.deleteTrademark.replace(':id', id)}`,
    msg: { error: '删除商标失败' },
    reducer: { name: 'deleteTrademarkResult' }
  });
}

// 批量删除商标
export function batchDeleteTrademark(ids) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'BATCH_DELETE_TRADEMARK',
    url: `${ApiTable.batchDeleteTrademark}`,
    data: { ids },
    msg: { error: '批量删除商标失败' },
    reducer: { name: 'batchDeleteTrademarkResult' }
  });
}

// 导入商标数据
export function importTrademark(formData) {
  return dispatch => basicAction({
    type: 'post',
    dispatch: dispatch,
    actionType: 'IMPORT_TRADEMARK',
    url: `${ApiTable.importTrademark}`,
    data: formData,
    msg: { error: '导入商标数据失败' },
    reducer: { name: 'importTrademarkResult' }
  });
}

// 导出商标数据
export function exportTrademark(params) {
  return dispatch => basicAction({
    type: 'get',
    dispatch: dispatch,
    actionType: 'EXPORT_TRADEMARK',
    url: `${ApiTable.exportTrademark}`,
    query: params,
    msg: { error: '导出商标数据失败' },
    reducer: { name: 'exportTrademarkResult' }
  });
} 